import requests
from bs4 import BeautifulSoup

# 目标URL
url = "https://jns.nju.edu.cn/CN/home"

# 伪装User-Agent
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0"
}

# 发送请求获取页面内容
response = requests.get(url, headers=headers)

# 检查请求是否成功
if response.status_code == 200:
    # 解析网页内容
    soup = BeautifulSoup(response.text, 'html.parser')

    # 打印网页标题
    print("网页标题:", soup.title.string)

    # 打印网页中的所有文字
    # .get_text() 方法会提取页面中的所有文本内容
    text_content = soup.get_text(separator='\n', strip=True)
    print("\n网页内容:")
    print(text_content)


else:
    print(f"无法访问页面，状态码: {response.status_code}")
